package mn.idax.exchange.otc.task;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.dangdang.elasticjob.lite.annotation.ElasticSimpleJob;
import mn.idax.exchange.otc.entity.OTCArbitration;
import mn.idax.exchange.otc.entity.OTCOrder;
import mn.idax.exchange.otc.enums.JiGuangPushEnum;
import mn.idax.exchange.otc.mapper.OTCArbitrationMapper;
import mn.idax.exchange.otc.mapper.OTCCertificateMapper;
import mn.idax.exchange.otc.service.JiGuangService;
import mn.idax.exchange.otc.service.OTCArbitrationService;
import mn.idax.exchange.otc.service.OTCOrderService;
import mn.idax.exchange.otc.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author: jack_huang
 * @Date: 2018/12/26 13:33
 */
@ElasticSimpleJob(cron="0 0/5 * * * ?")
@Component
public class JiGuangArbitrationJob implements SimpleJob {

    @Autowired
    private OTCArbitrationService otcArbitrationService;

    @Autowired
    private OTCArbitrationMapper otcArbitrationMapper;

    @Autowired
    private OTCOrderService otcOrderService;

    @Autowired
    private JiGuangService jiGuangService;



    @Override
    public void execute(ShardingContext shardingContext) {
        //获取仲裁订单已过36小时的仲裁请求
        List<OTCArbitration> arbitrations = otcArbitrationService.getNeedJiGuangPush(DateUtils.getUTCNow());
        if (!arbitrations.isEmpty()){
            for (OTCArbitration arbitration : arbitrations) {
                OTCOrder otcOrder = otcOrderService.selectByPrimaryKey(arbitration.getOrderid());

                //极光推送给双方  您的{0}仲裁订单将满48小时，会被自动处理，请及时操作
                jiGuangService.pushToBuyerAndSeller(otcOrder, JiGuangPushEnum.ARBITRATION_WILLEXPIRE);
                //推送完更新
                otcArbitrationMapper.updateJiGuangPushIsTrue(arbitration.getId());
            }
        }



    }
}
